package com.yangzhe.interview.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.yangzhe.base.base.BaseFragment;
import com.yangzhe.base.utils.LogUtil;
import com.yangzhe.base.utils.ToastUtils;
import com.yangzhe.interview.R;
import com.yangzhe.interview.bean.TestBean;
import com.yangzhe.okhttputils.OkHttpUtils;
import com.yangzhe.okhttputils.callback.StringCallback;

/**
 * 杨哲  版权所有(c)
 * Author：yangzhe
 * Time: 2017/5/17 19:43
 * <p>
 * 功能描述:
 */
public class InterViewFragment extends BaseFragment {

    TextView mInterviewTxtMain;

    public static InterViewFragment newInstance() {
        return new InterViewFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.interview_fragment_home;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mInterviewTxtMain = (TextView) view.findViewById(R.id.interview_txt_main);
        mInterviewTxtMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getDataFromServer();
            }
        });
    }

    private void getDataFromServer() {

        OkHttpUtils.get("https://www.qsygo.com/interface.php/index/carousel")
                .params("username", "yangzhe")
                .params("password", "1234")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(String response) {
                        LogUtil.e("test", "结果为:  " + response);
                        TestBean testBean = JSON.parseObject(response, TestBean.class);
                        if (testBean != null) {
                            ToastUtils.showToast("解析正常:  " + testBean.getClick());
                        } else {
                            ToastUtils.showToast("解析错误");
                        }
                    }
                });

    }


}
